package com.mapbar.ure.backend;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mapbar.ure.utils.ChangingMonitorHashSet;

/**
 * NFA节点实现
 * 
 * @author QIN Jian
 * 
 * @param <T>
 */
public class NFANode<T> {

	private Map<T, List<NFANode<T>>> next = new HashMap<T, List<NFANode<T>>>();

	// boolean isEndStatus = false;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HashMap<String, String> map = new HashMap<String, String>();
		// map.put(null, null);
		map.put(null, "asdf");
		System.out.println(map.containsKey(null));
	}

	public void addNext(T c, NFANode<T> start) {
		if (getNext().containsKey(c)) {
			getNext().get(c).add(start);
		} else {
			List<NFANode<T>> value = new ArrayList<NFANode<T>>();
			value.add(start);
			getNext().put(c, value);
		}
	}

	public void eClosure(ChangingMonitorHashSet<NFANode<T>> set) {
		if (!getNext().containsKey(null)) {
			return;
		}

		set.addAll(getNext().get(null));
		if (set.hasAdded()) {
			for (NFANode<T> node : getNext().get(null)) {
				node.eClosure(set);
			}
		} else {
			return;
		}
	}

	public Map<T, List<NFANode<T>>> getNext() {
		return next;
	}

	public void setNext(Map<T, List<NFANode<T>>> next) {
		this.next = next;
	}
}
